package zy1220.zy3;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class demo {
    public static void main(String[] args) throws Exception {
        SAXReader reader = new SAXReader();
        Document read = reader.read("D:\\ideadashuju12\\liu_ya_kai\\src\\zy1220\\zy3\\web.xml");
        Element root = read.getRootElement();
        HashMap<String, String> map = new HashMap<>();
        List<Element> list = root.elements("servlet-mapping");
        for (Element e : list) {
            map.put(e.elementText("url-pattern"),e.elementText("servlet-name"));
        }
        List<Element> list1 = root.elements("servlet");
        for (Element e : list1) {
            for (String s : map.keySet()) {
                if (e.elementText("servlet-name").equals(map.get(s))){
                    map.put(s,e.elementText("servlet-class"));
                }
            }
        }
        System.out.println(map);
        System.out.println("请输入");
        String s = new Scanner(System.in).nextLine();
        for (String s1 : map.keySet()) {
            if (s1.contains(s)){
                Class<?> aClass = Class.forName(map.get(s1));
                Object o = aClass.newInstance();
                Method m = aClass.getDeclaredMethod("doGet");
                m.invoke(o);

            }

        }

    }
}
